#coding:utf-8
'''
Created on 2012-6-30

@author: wb_suoyao.shen
'''
from django.db import models,connection, transaction

class LinksManager(models.Manager):
    def deleteLinksBatch(self,ids=None):
        sql = '''
                DELETE FROM links_links WHERE 1=1 
            '''
        if ids is not None:
            cond = 'AND id IN ('
            for i in ids:
                cond += i + ','
            cond = cond[:-1] + ')'
        cursor = connection.cursor()
        cursor.execute(sql + cond)
        transaction.commit_unless_managed()
        cursor.close()
        return None

class Links(models.Model):
    title = models.CharField(max_length=2560,null=True, blank=True)
    recdurl = models.CharField(max_length=2560,null=True, blank=True)
    description = models.CharField(max_length=5120,null=True, blank=True)
    create_time = models.DateTimeField(null=True,blank=True)
    objects = LinksManager()
    
    def __unicode__(self):
        return self.title
    
    class Meta:
        ordering = ['-create_time']
        
    class Admin:
        list_display = ('title','recdurl','description','create_time')
        fields = (
            (None,{'fields':('title','recdurl','description','create_time')}),
        )